package springbotwebmvc.demo.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * {@link HelloWorldController}通知  先于指定的controller
 * @Author acy
 * @Date 2019/04/29
 */
@ControllerAdvice(assignableTypes = HelloWorldController.class)
public class HelloWorldControllerAdvice {

	@ModelAttribute("acceptLanguage")
	public String getRequestHead(@RequestHeader("Accept-Language")String acceptLanguage){
		return acceptLanguage;
	}

	@ModelAttribute("jSessionId")
	public String getJSessionId(@CookieValue("JSESSIONID")String jSessionId){
		return jSessionId;
	}

	@ExceptionHandler(Throwable.class)
	public ResponseEntity<String> onException(Throwable throwable){
		return ResponseEntity.ok(throwable.getMessage());
	}
}
